package lib

import (
	"github.com/gin-gonic/gin"
	"lib/mall/v1/plugins"
)


type ContextOptionFunc func(*Context)

func HandlerFunc(handler ContextOptionFunc) gin.HandlerFunc {
	return func(ctx *gin.Context) {
		option := &Context{
			Context: ctx,
			Db:      plugins.Db(),
		}
		handler(option)
	}
}

// TransHandlerFunc lib.HandlerFunc  转换为 gin.HandlerFunc
func TransHandlerFunc(handlers ...ContextOptionFunc) []gin.HandlerFunc {
	RHandlers := make([]gin.HandlerFunc, 0)
	for _, handle := range handlers {
		RHandlers = append(RHandlers, HandlerFunc(handle))
	}
	return RHandlers
}
